// 监听者
export default class Subsciption {
    subsciptions: Array<Observer>
    constructor() {
        this.subsciptions = []
    }
    add(observer: Observer) {
        this.subsciptions.push(observer)
    }
    remove(observer: Observer) {
        this.subsciptions = this.subsciptions.filter(item => item !== observer)
    }
    clear() {
        this.subsciptions.length = 0
    }
    notify() {
        this.subsciptions.forEach(item => {
            item.uptade()
        })
    }
}
// 观察者
export class Observer {
    name: string;
    count: number
    constructor(name: string) {
        this.name = name
        this.count = 0
    }
    uptade() {
        this.count++

    }
}